var timeLog = function timeLog(req, res, next) {
    console.log('Time: ', Date.now());
    console.log('URL: ', req.originalUrl);
    console.log('--------------------------------');
    next();
};


var callBackForAll = function callBackForAll(req, res, next) {
    console.log("callBackForAll");
    console.log('--------------------------------');
    next();
};

exports.route = function (app) {
    app.use(timeLog);

    app.all('/', function (req, res, next) {
        console.log('app.all');
        console.log('--------------------------------');
        next() // pass control to the next handler
    }, callBackForAll);

    app.param('id', function (req, res, next, value) {
        console.log('app.param  ', value);
        console.log('--------------------------------');
        next();
    })

    app.get('/', function (req, res) {
        console.log('app.get 1');
        console.log('--------------------------------');
        res.redirect('/1.html');
    });

    app.get('/test', function (req, res) {
        console.log('app.get 2');
        console.log('--------------------------------');
        res.redirect('/2.html');
    });

    app.get('/test/:id', function (req, res) {
        console.log('app.get id');
        console.log('--------------------------------');
        res.send(req.params.id);
    });

    app.get('/test2/:id', function (req, res, next) {
        var id = req.params.id;
        console.info("app.get 2 function 1  id=" + id);
        console.log('--------------------------------');
        if (id == 0) {
            next('route');
        }
        else {
            next();
        }
    }, function (req, res, next) {
        var id = req.params.id;
        console.info("app.get 2 function 2  id=" + id);
        console.log('--------------------------------');
        res.send(id)
    });

    app.get('/test2/:id', function (req, res, next) {
        console.log('app.get 2 id');
        console.log('--------------------------------');
        res.end('/test2/:id');
    })


    app.use('/test3/:id/:name', function (req, res, next) {
        var id = req.params.id;
        var name = req.params.name;
        console.info("app.use 3 function 1  id=" + id + " name=" + name);
        console.log('--------------------------------');
        if (id == 0) {
           next('route');
        }
        else {
            next();
        }
    }, function (req, res, next) {
        var id = req.params.id;
        var name = req.params.name;
        console.info("app.use 3 function 2  id=" + id + " name=" + name);
        console.log('--------------------------------');
        res.send(id)
    });

    app.get('/test3/:id/:name', function (req, res, next) {
        console.log('app.get 3 id');
        console.log('--------------------------------');
        res.end('/test3/:id');
    })
}